package com.codeoss.framework.view.util;

import org.springframework.stereotype.Component;

import com.codeoss.framework.data.metadata.Column;
import com.codeoss.framework.data.metadata.Table;
import com.codeoss.framework.view.component.Page;

@Component
public class ViewUtil {
	public String getViewType(Table table,Column column) {
		String dataType = column.getDataType();
		String viewType = "text";
		if(column.isPrimaryKey()) {
			if(table.getParentColumn()==null) {
				viewType="hidden";
			}else {
				viewType="label";
			}
		}else if ("string".equals(dataType)) {
			viewType = "text";
		} else if ("long".equals(dataType) || "bigdecimal".equals(dataType) || "integer".equals(dataType)) {
			viewType = "number";
		} else if ("datetime".equals(dataType)) {
			viewType = "datetime";
		} else if ("date".equals(dataType)) {
			viewType = "date";
		} else if ("time".equals(dataType)) {
			viewType = "time";
		} else if ("boolean".equals(dataType)) {
			viewType = "checkbox";
		}
		if (column.getLookupInfo() != null) {
			viewType = "select";
		}
		return viewType;
	}
	
	public boolean isSearchPage(Page page) {
		String pageBean=page.getPageBean();
		if("listViewPageBean".equals(pageBean)||"searchViewPageBean".equals(pageBean)||
			"mSearchViewPageBean".equals(pageBean)) {
			return true;
		}
		return false;
	}
}
